<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="工序编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['fnumber']" placeholder="请输入工序编号"></a-input>
        </a-form-item>
        <a-form-item label="工序名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['fname']" placeholder="请输入工序名称"></a-input>
        </a-form-item>
        <a-form-item label="工序内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['fcontent']" placeholder="请输入工序内容"></a-input>
        </a-form-item>
        <a-form-item label="单件工时" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['producers']" placeholder="请输入单件工时"></a-input>
        </a-form-item>
        <a-form-item label="单件最大工时" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['maxproducers']" placeholder="请输入单件最大工时"></a-input>
        </a-form-item>
        <a-form-item label="车间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-select-depart v-decorator="['depart']"/>
        </a-form-item>
        <a-form-item label="工作地" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['gzarea']" placeholder="请输入工作地"></a-input>
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['desp']" rows="4" placeholder="请输入备注"/>
        </a-form-item>
        <a-form-item label="工时百分比" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['bfb']" placeholder="请输入工时百分比"></a-input>
        </a-form-item>
        <a-form-item label="工时单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['punit']" :trigger-change="true" dictCode="punit" placeholder="请选择工时单位"/>
        </a-form-item>
        <a-form-item label="检验确认方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['pstyle']" :trigger-change="true" dictCode="pstyle" placeholder="请选择检验确认方式"/>
        </a-form-item>
        <a-form-item label="工序类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['gxinfo']" :trigger-change="true" dictCode="gxinfo" placeholder="请选择工序类型"/>
        </a-form-item>
        <a-form-item label="准终工时" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['zprocedure']" placeholder="请输入准终工时"></a-input>
        </a-form-item>
        <a-form-item label="路线点" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['lxd']" placeholder="请输入路线点"></a-input>
        </a-form-item>
        <a-form-item label="生产计价方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['pricestyle']" :trigger-change="true" dictCode="pricestyle" placeholder="请选择生产计价方式"/>
        </a-form-item>
        <a-form-item label="工时单价" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['price']" placeholder="请输入工时单价"></a-input>
        </a-form-item>
        <a-form-item label="开工类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['kglx']" :trigger-change="true" dictCode="kglx" placeholder="请选择开工类型"/>
        </a-form-item>
        <a-form-item label="生产人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-select-user-by-dep v-decorator="['scry']"/>
        </a-form-item>
        <a-form-item label="质检通知人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-select-user-by-dep v-decorator="['zztz']"/>
        </a-form-item>
        <a-form-item label="上传附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-upload v-decorator="['uploadfile1']" :trigger-change="true"></j-upload>
        </a-form-item>
        <a-form-item label="工序分类" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['procinfo']" placeholder="请输入工序分类"></a-input>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JUpload from '@/components/jeecg/JUpload'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  
  export default {
    name: "ProgrammModal",
    components: { 
      JUpload,
      JSelectDepart,
      JSelectUserByDep,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/Programm/programm/add",
          edit: "/Programm/programm/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'fnumber','fname','fcontent','producers','maxproducers','depart','gzarea','desp','bfb','punit','pstyle','gxinfo','zprocedure','lxd','pricestyle','price','kglx','scry','zztz','uploadfile1','procinfo'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'fnumber','fname','fcontent','producers','maxproducers','depart','gzarea','desp','bfb','punit','pstyle','gxinfo','zprocedure','lxd','pricestyle','price','kglx','scry','zztz','uploadfile1','procinfo'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>